var F_Retentioncount_Entrance = {
    _init: function () {
        if (B_Login._checkUpdate(), M_HeadFoot._headShow(1), "demo" != M_Init._controller && B_User._isDemoUser())B_Login._openLogin("background"); else {
            switch (M_Init._clean(), M_Init._controller) {
                case"demo":
                    M_Init._api.innerRetentionCount = "demoInnerRetentionCount";
                    break;
                default:
                    M_Init._api.innerRetentionCount = "innerRetentionCount"
            }
            M_Init._dateCache.begin = M_Init._dateChoose.begin, M_Init._dateCache.end = M_Init._dateChoose.end, M_Common._getOrderGame("retentioncount", "", "1-3"), B_Date._chooseSection({
                autoCommit: !1,
                todayValid: !1
            }, 1, M_Init._dateChoose.begin, M_Init._dateChoose.end, function (t, e) {
                t == M_Init._dateCache.begin && M_Init._dateCache.end == e || (M_Init._dateCache.begin = t, M_Init._dateCache.end = e, F_Retentioncount_Info._getInfo())
            })
        }
    }
}, F_Retentioncount_Info = {
    _init: [{
        type: "together",
        name: "新增玩家留存",
        tab: [],
        tips: [{position: "first", content: "当日新增玩家在次日、7日后、30日后的留存人数占新增玩家的比例"}]
    }, {
        type: "tableColSpan",
        name: "自定义留存",
        tab: [],
        tips: [{position: "first", content: "新增玩家（活跃玩家、付费玩家）在之后第N日（周、月）的留存率（留存人数）"}]
    }],
    _tab: [{key: "day", name: "每日", tips: ""}, {key: "week", name: "每周", tips: ""}, {
        key: "month",
        name: "每月",
        tips: ""
    }],
    _drop: [[{key: "new", name: "新增玩家"}, {key: "active", name: "活跃玩家"}, {key: "paid", name: "付费玩家"}], [{
        key: "",
        name: "留存率"
    }, {key: "num", name: "留存数"}]],
    _port: [[[{name: "次日留存率", key: "game_retention|y_axis_retention_rate_1d"}, {
        name: "7日留存率",
        key: "game_retention|y_axis_retention_rate_7d"
    }, {name: "30日留存率", key: "game_retention|y_axis_retention_rate_30d"}]], [[{
        name: "自定义留存",
        key: "retention_custom"
    }]]],
    _domInit: function () {
        M_Inside._htmlChartTable($("#ct_main_area"),
            F_Retentioncount_Info._init),
            $("#bs_table_1_0").addClass("tableArea-color-change").prepend("<span>玩家样本：所选日期内</span>" + F_Retentioncount_Info._htmlTab() + F_Retentioncount_Info._htmlDrop()),
        M_Init._dataCache.SelfDefineSave || (M_Init._dataCache.SelfDefineSave = ["day", "new", ""]), $("#bs_table_1_0 .tg-tab-btn li").each(function () {
            $(this).click(function () {
                $(this).hasClass("tg-tab-btn-selected") || ($(this).addClass("tg-tab-btn-selected").siblings("li").removeClass("tg-tab-btn-selected"), M_Init._dataCache.SelfDefineSave[0] = $(this).attr("data-i"), F_Retentioncount_Info._chartHtml(1, 0))
            })
        }), F_Retentioncount_Info._dropSelect("tg-selected-drop-0", 1), F_Retentioncount_Info._dropSelect("tg-selected-drop-1", 2), M_Inside._dropShow(), M_Inside._dropLeave(), F_Retentioncount_Info._getInfo(), M_Inside._downloadCsv()
    },
    _dropSelect: function (t, e) {
        $("#" + t + " ul li a").click(function () {
            var t = $(this).text(), n = $(this).attr("data-i"), a = $(this).parents(".tg-selected-drop").find("p span").attr("data-i");
            $(this).parents(".tg-selected-drop").find("p span").html(t).attr("data-i", n), $(this).parents(".tg-selected-drop").children("ul").hide(), a != n && (M_Init._dataCache.SelfDefineSave[e] = n, F_Retentioncount_Info._chartHtml(1, 0))
        })
    },
    _htmlTab: function () {
        var t = "";
        t += '<ul class="tg-tab-btn fl">';
        for (var e = 0; e < F_Retentioncount_Info._tab.length; e++)t += '<li class="tg-tab-btn-normal tip-hover', 0 == e && (t += " tg-tab-btn-selected"), t += '" data-i="' + F_Retentioncount_Info._tab[e].key + '">' + F_Retentioncount_Info._tab[e].name, F_Retentioncount_Info._tab[e].tips && (t += '<div class="tip-box-show">', t += '<i class="triangle-up"></i>', t += '<div class="tip-box-content">', t += F_Retentioncount_Info._tab[e].tips, t += "</div>", t += "</div>"), t += "</li>";
        return t += "</ul>"
    },
    _htmlDrop: function () {
        for (var t = "", e = 0; e < F_Retentioncount_Info._drop.length; e++) {
            t += '<div class="tg-selected-drop" id="tg-selected-drop-' + e + '">';
            for (var n = 0; n < F_Retentioncount_Info._drop[e].length; n++)0 == n && (t += '<p class="tg-drop-text-part"><i class="tg-graph tg-triangle-gray-bottom"></i><span data-i="' + F_Retentioncount_Info._drop[e][n].key + '" >' + F_Retentioncount_Info._drop[e][n].name + "</span></p><ul>"), t += '<li><a data-i="' + F_Retentioncount_Info._drop[e][n].key + '">' + F_Retentioncount_Info._drop[e][n].name + "</a></li>";
            t += "</ul></div>"
        }
        return t
    },
    _getInfo: function () {
        for (var t = M_Init._dateCache.begin, e = M_Init._dateCache.end, n = [], a = 0; a < F_Retentioncount_Info._init.length; a++)n.push("bs_chart_" + a + "_0");
        var _ = {};
        _.start_date = t, _.end_date = e, _.game_id = M_Init._gameId, _ = B_Common._postData(_), B_Port._ajax(M_Init._api.innerRetentionCount, "get", !0, _, function () {
            for (var t = 0; t < n.length; t++)$("#" + n[t]).html(B_Pre._loading())
        }, function () {
            for (var t = 0; t < n.length; t++)$("#" + n[t]).html("")
        }, function (t, e) {
            if (t) {
                M_Init._dataCache.data = t;
                for (var n = 0; n < F_Retentioncount_Info._init.length; n++)F_Retentioncount_Info._chartHtml(n, "0", t), M_Inside._chartTableIcon(F_Retentioncount_Info._init[n].type, n, "0")
            }
        }, function (t, e, a) {
            for (var _ = 0; _ < n.length; _++)$("#" + n[_]).html(B_Pre._empty(e))
        })
    },
    _chartHtml: function (t, e) {
        M_Init._dataCache["position_" + t] = e;
        var n = M_Init._dataCache.data, a = {
            x_axis: [],
            y_axis: [],
            xFormatDate: !0,
            yFormat: ""
        }, _ = "", o = {head: [], body: []};
        switch (t + "") {
            case"0":
                a.yFormat = "%", a.tooltip = {num: 3, unit: "%"}, _ = "%", o = {head: ["日期"], body: []}
        }
        for (var i = 0; i < F_Retentioncount_Info._port[t][e].length; i++) {
            var d = F_Retentioncount_Info._port[t][e][i].key.split("|"), r = F_Retentioncount_Info._port[t][e][i].name;
            switch (t + "") {
                case"0":
                    if (n[d[0]][d[1]]) {
                        o.head.push(r);
                        var s = n[d[0]][d[1]];
                        a.x_axis = n[d[0]].x_axis;
                        for (var c = 0; c < s.length; c++)o.body[c] || (o.body[c] = [n[d[0]].x_axis[c]]), "%" != _ ? o.body[c].push(s[c]) : o.body[c].push(s[c] + _);
                        a.y_axis.push({name: r, data: s})
                    }
                    break;
                case"1":
                    var h = "retention_custom_" + M_Init._dataCache.SelfDefineSave[0];
                    switch (M_Init._dataCache.SelfDefineSave[2] && (h += "_" + M_Init._dataCache.SelfDefineSave[2]), "num" != M_Init._dataCache.SelfDefineSave[2] && (_ = "%"), M_Init._dataCache.SelfDefineSave[0] + "") {
                        case"day":
                            o = {
                                colspan: "第N天后留存玩家",
                                head: ["首次使用日期", "", "1天后", "2天后", "3天后", "4天后", "5天后", "6天后", "7天后", "14天后", "30天后"],
                                body: []
                            };
                            break;
                        case"week":
                            o = {
                                colspan: "第N周后留存玩家",
                                head: ["首次使用日期", "", "1周后", "2周后", "3周后", "4周后", "5周后", "6周后", "7周后", "8周后", "9周后"],
                                body: []
                            };
                            break;
                        case"month":
                            o = {
                                colspan: "第N月后留存玩家",
                                head: ["首次使用日期", "", "1月后", "2月后", "3月后", "4月后", "5月后", "6月后", "7月后", "8月后", "9月后"],
                                body: []
                            }
                    }
                    switch (M_Init._dataCache.SelfDefineSave[1] + "") {
                        case"new":
                            o.head[1] = "新增玩家数";
                            break;
                        case"active":
                            o.head[1] = "活跃玩家数";
                            break;
                        case"paid":
                            o.head[1] = "付费玩家数"
                    }
                    if (n[d[0]] && n[d[0]][h] && n[d[0]][h][M_Init._dataCache.SelfDefineSave[1]])for (var s = n[d[0]][h][M_Init._dataCache.SelfDefineSave[1]], c = 0; c < s.length; c++)switch (o.body[c] || (o.body[c] = [s[c].data_date]), o.body[c].push(s[c].user_num), M_Init._dataCache.SelfDefineSave[0] + "") {
                        case"day":
                            o.body[c].push(s[c].rate_1d + _), o.body[c].push(s[c].rate_2d + _), o.body[c].push(s[c].rate_3d + _), o.body[c].push(s[c].rate_4d + _), o.body[c].push(s[c].rate_5d + _), o.body[c].push(s[c].rate_6d + _), o.body[c].push(s[c].rate_7d + _), o.body[c].push(s[c].rate_14d + _), o.body[c].push(s[c].rate_30d + _);
                            break;
                        case"week":
                            o.body[c].push(s[c].rate_1w + _), o.body[c].push(s[c].rate_2w + _), o.body[c].push(s[c].rate_3w + _), o.body[c].push(s[c].rate_4w + _), o.body[c].push(s[c].rate_5w + _), o.body[c].push(s[c].rate_6w + _), o.body[c].push(s[c].rate_7w + _), o.body[c].push(s[c].rate_8w + _), o.body[c].push(s[c].rate_9w + _);
                            break;
                        case"month":
                            o.body[c].push(s[c].rate_1m + _), o.body[c].push(s[c].rate_2m + _), o.body[c].push(s[c].rate_3m + _), o.body[c].push(s[c].rate_4m + _), o.body[c].push(s[c].rate_5m + _), o.body[c].push(s[c].rate_6m + _), o.body[c].push(s[c].rate_7m + _), o.body[c].push(s[c].rate_8m + _), o.body[c].push(s[c].rate_9m + _)
                    }
            }
        }
        switch (o.name = M_Inside._tableName(F_Retentioncount_Info._init, t, e, M_Init._dateCache.begin, M_Init._dateCache.end), M_Init._dataCache[t + "_" + e] = o, t + "") {
            case"0":
                M_Inside_Chart._chartData(50, "bs_chart_" + t + "_" + e, a)
        }
        M_Inside._tableHtml(1, t + "_" + e)
    }
};